﻿<!DOCTYPE html>
<html>
<head>
    <script src="../../js/header.js"></script>
    <script src="../../lib/date/wdatepicker.js"></script>
</head>
<body>
    <section class="container-fluid" style="background-color: white;">
        <form class="form-horizontal m15_t" id="form">
            <div class="tab-content">
                <div class="tab-pane fade in active" id="divOrderNo">

                    <div class="form-group" id="divShowOrderNo" style="display:none;">
                        <label class="wd100 control-label">订 单 号：</label>
                        <div class="wd250 m15_l">
                            <label class="form-control" id="labOrderNo"></label>
                        </div>
                    </div>
                    <div class="form-group" id="divShowOrderDate" style="display:none;">
                        <label class="wd100 control-label"></label>
                        <div class="wd250 m15_l">
                            <label id="labOrderDate"></label>
                        </div>
                    </div>

                    <div class="form-group" id="divOrderDate">
                        <label class="wd100 control-label"><span class="WdateFmtErr">*</span>下单日期：</label>
                        <div class="wd250 m15_l">
                            <input class="form-control Wdate" type="text" name="orderDate" onfocus="WdatePicker({minDate:'%y-%M-{%d}'})" />
                        </div>
                    </div>
                    <div class="form-group" id="divDepositAmount">
                        <label class="wd100 control-label"><span class="WdateFmtErr">*</span>押金金额：</label>
                        <div class="wd250 m15_l">
                            <input class="form-control" type="text" name="depositAmount" maxlength="10" />
                        </div>
                    </div>
                    <div class="form-group" id="divDepositDate">
                        <label class="wd100 control-label"><span class="WdateFmtErr">*</span>押金交付日期：</label>
                        <div class="wd250 m15_l">
                            <input class="form-control Wdate" type="text" name="depositDate" onfocus="WdatePicker()" />
                        </div>
                    </div>

                    <div class="form-group" id="divReceiptDate">
                        <label class="wd100 control-label"><span class="WdateFmtErr">*</span>收货日期：</label>
                        <div class="wd250 m15_l">
                            <input class="form-control Wdate" type="text" name="receiptDate" onfocus="WdatePicker()" />
                        </div>
                    </div>
                    <div class="form-group" id="divPayDate">
                        <label class="wd100 control-label"><span class="WdateFmtErr">*</span>付款日期：</label>
                        <div class="wd250 m15_l">
                            <input class="form-control Wdate" type="text" name="payDate" onfocus="WdatePicker()" />
                        </div>
                    </div>
                </div>
            </div>
            <input type="hidden" value="0" id="isCanEdit" />
        </form>
    </section>
    <script type="text/javascript">
        var validator = null;
        $(function () {
            var orderNo = FlashPay.Util.GetQueryString("orderNo");
            if (orderNo != null && orderNo != undefined) {
                var type = FlashPay.Util.GetQueryString("type");
                var url = "/Order/Get";
                if (type == 3) { //收货日期
                    url = "/Order/GetReceiptDatePermission";
                } else if (type == 2) {//付款日期
                    url = "/Order/GetPayDatePermission";
                }
                showOrderInfo(orderNo, url, type);
            } else {
                var nowDate = new Date().toLocaleDateString().split('/').join('-');     //获取当前日期
                $("input[name='orderDate']").val(nowDate);
            }
            validator = FlashPay.Util.Validator({
                formObj: $("#form"),
                rules: {
                    orderDate: {
                        required: true
                    },
                    depositAmount: {
                        required: true, money: true, isFloatGtZero: true
                    },
                    depositDate: {
                        required: true
                    },
                    receiptDate: {
                        required: true
                    },
                    payDate: {
                        required: true
                    }
                },
                messages: {
                    orderDate: {
                        required: "下单日期不能为空"
                    },
                    depositAmount: {
                        required: "押金金额不能为空", money: "押金金额必须为金额，最多保留两位小数", isFloatGtZero: "押金金额必须大于0"
                    },
                    depositDate: {
                        required: "押金交付日期不能为空"
                    },
                    receiptDate: {
                        required: "收货日期不能为空"
                    },
                    payDate: {
                        required: "付款日期不能为空"
                    }
                }
            });
        });

        function showOrderInfo(orderNo, url, type) {
            FlashPay.Util.Ajax({
                type: "POST",
                url: url,
                data: JSON.stringify({ orderNo: orderNo }),
                dataType: "json",
                contentType: "application/json",
                success: function (data) {
                    if (data.totalCount > 0) {
                        var infos = data.result[0];

                        if (type > 0) { //付款审核
                            $("#divOrderDate").remove(); $("#divDepositAmount").remove(); $("#divDepositDate").remove();
                        }
                        if (type == 2) { //付款日期
                            $("#divReceiptDate").remove();
                        }
                        if (type == 3) { //收货日期
                            $("#divPayDate").remove();
                        }
                        if (type >= 2) {
                            $("#divShowOrderNo").show();
                            $("#divShowOrderDate").show();
                            $("#labOrderNo").text(orderNo);
                        }
                        FlashPay.Util.SetInputVal("orderDate", FlashPay.Util.GetDateByTime(infos.orderDate));
                        FlashPay.Util.SetInputVal("depositDate", FlashPay.Util.GetDateByTime(infos.depositDate));//押金交付日期
                        FlashPay.Util.SetInputVal("receiptDate", FlashPay.Util.GetDateByTime(infos.receiptDate));//收货日期
                        FlashPay.Util.SetInputVal("payDate", FlashPay.Util.GetDateByTime(infos.payDate));        //付款日期
                        FlashPay.Util.SetInputVal("depositAmount", infos.depositAmount);                         //押金金额
                    }
                }
            });
        }

        function save() {
            if ($("body").data("confirmReceive") == "lock") {
                return false;
            } else {
                $("body").data("confirmReceive", "lock");
            }

            if (!validator.form()) {
                return false;
            }

            var orderModel = {};
            var url = "/Order/Add";

            var orderNo = FlashPay.Util.GetQueryString("orderNo");
            var type = FlashPay.Util.GetQueryString("type");
            if (type == 0 || type == 4) {
                orderModel.depositAmount = $('input[name="depositAmount"]').val();
                orderModel.depositDate = $("input[name='depositDate']").val();
                orderModel.orderDate = $("input[name='orderDate']").val();
                orderModel.receiptDate = $("input[name='receiptDate']").val();
                orderModel.payDate = $('input[name="payDate"]').val();
            }

            if (orderNo != null && orderNo != undefined) {
                switch (parseInt(type)) {
                    case 0:
                        url = "/Order/Edit";//编辑所有
                        break;
                    case 2:    //编辑付款日期
                        url = "/Order/EditPayDate";
                        orderModel.payDate = $('input[name="payDate"]').val();
                        break;
                    case 3:   //编辑收货日期
                        url = "/Order/EditReceiptDate";
                        orderModel.receiptDate = $("input[name='receiptDate']").val();
                        break;
                }
                orderModel.orderNo = orderNo;
            }
            operating(orderModel, url);
        }

        function operating(orderModel, url) {
            FlashPay.Util.Ajax({
                type: "POST",
                url: url,
                data: JSON.stringify(orderModel),
                dataType: "json",
                contentType: "application/json",
                success: function (data) {
                    if (!data.success) {
                        //FlashPay.UI.Tip_danger(data.message == null ? "操作失败！" : data.message);
                        FlashPay.UI.Tip_short_danger(data.message == null ? "操作失败！" : data.message);
                        return;
                    } else {
                        FlashPay.UI.DialogOpener().Tip_success(data.message == null ? "操作成功！" : data.message);
                        FlashPay.UI.DialogOpener().doSearch();
                        FlashPay.UI.CloseDialog();
                    }
                    $("body").data("confirmReceive", "unlock");
                }
            });
        }
    </script>
</body>
</html>